package us.mooresr.aircraftscheduling.client.events;

import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.EventHandler;
import us.mooresr.aircraftscheduling.shared.model.User;
import com.google.gwt.event.shared.HasHandlers;
import com.google.gwt.event.shared.HandlerRegistration;

public class UserChangedEvent extends
		GwtEvent<UserChangedEvent.UserChangedHandler> {

	public static Type<UserChangedHandler> TYPE = new Type<UserChangedHandler>();
	private User user;

	public interface UserChangedHandler extends EventHandler {
		public void onUserChanged(UserChangedEvent event);
	}

	public interface UserChangedHasHandlers extends HasHandlers {
		public HandlerRegistration addUserChangedHandler(UserChangedHandler handler);
	}

	public UserChangedEvent(User user) {
		this.user = user;
	}

	public User getUser() {
		return user;
	}

	@Override
	protected void dispatch(UserChangedHandler handler) {
		handler.onUserChanged(this);
	}

	@Override
	public Type<UserChangedHandler> getAssociatedType() {
		return TYPE;
	}

	public static Type<UserChangedHandler> getType() {
		return TYPE;
	}

	public static void fire(HasHandlers source, User user) {
		source.fireEvent(new UserChangedEvent(user));
	}
}
